<?php
include_once("../module/checkA.php");
include_once("../../config.php");

/* 权限判断 */
////admin_priv('order');

$plate=select_one_line_all_items($table_Prefix."plate","mid = 'order'");

$emp_id = $_SESSION['nid'];

//用来判断当前系统属于什么板块
$system_part = $plate['mid'];
include_once("select_datas.php");


$emp_list_array=transform_2darray_in_1darray_number_as_key($detail,"agent");
$emp_rank_str=implode($emp_list_array,"','");

$emp_rank=select_lines_items($table_prefix."employee","","name,nid","nid in ('".$emp_rank_str."')","");
$emp_list=transform_2darray_in_1darray_with_new_key($emp_rank,"nid","name");
?>




<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php include_once(ROOT_PATH_.'/controlbase/module/head.php'); ?>
</head>

<body>

<div id="topbar">
    <?php include ROOT_PATH_ . '/controller/common/module/topbar.php'; ?>
</div>

<div id="container" class="<? echo $system_part ?>">

    <div id="maincontent">

        <div id="sidebar">
            <?php include ROOT_PATH_ . '/controller/common/module/sidebar.php'; ?>
        </div>


<div id="content">
<?php $page_title='个人订单';?>
<?php include ROOT_PATH_.'/controlbase/module/mod-page-title.php'; ?>




	<?php include 'mod-search.php'; ?>




    <div class=" layui-form">
        <button class="layui-btn layui-btn-sm" id="quanxuan"><i class="layui-icon">&#x1005;</i>全选</button>
        <button class="layui-btn layui-btn-sm" id="buxuan"><i class="layui-icon">&#xe63f;</i>不选</button>
        <button class="layui-btn layui-btn-sm" id="cancel_order">取消选中订单</button>
        <button class="layui-btn layui-btn-sm" id="deal_order">  确认选中出单</button>
        <a class="layui-btn layui-btn-sm" href="../collect.php?sys_part=<?php echo $system_part?>"><i class="fa fa-bar-chart-o" aria-hidden="true"></i>  统计</a>
        <a class="layui-btn layui-btn-sm" href="../detail-add.php?nav-itemed=unit&sys_part=<?php echo $system_part?>"><i class="layui-icon">&#xe608;</i>  新增</a>
    </div>

    <hr />







<!-- 用$system_part .list_boxes来控制来到确认板块信息显示-->
<div class="list-box">

<div class="list-boxes">








<table class="layui-table">
  <colgroup>
    <col width="60">
    <col width="150">
	
	<col >
	<col >
	<col >
	<col >
	<col >
	<col >
	<col width="250">

  </colgroup>
  <thead>
    <tr>



      <th>序号</th>
      <th>客户</th>
      <th>订单号</th>
      <th>价格</th>
      <th>税后价</th>
      <th>状态</th>
      <th>下单时间</th>
<!--      <th>部门</th>-->
      <th>业务员</th>
      
      <th>操作</th>
    </tr>
  </thead>
  <tbody>

  <?php

  if ($detailnum == 0) {
      echo "<tr><td colspan='6'>暂无数据</td></tr>";
  }

  ?>


	<?php
	for ($i = 0; $i < $detailnum; $i++) {
		
		
    ?>

    <tr id="item<?echo $detail[$i]['nid']?>" >
      <td><input type="checkbox" value="<?echo $detail[$i]['nid']?>" name="nid[]" class="" ></td>
      <td><? echo $detail[$i]['name']?></td>
      <td><? echo $detail[$i]['order_sn']?></td>
      <td><? echo $detail[$i]['price']?></td>
      <td><? echo $detail[$i]['price']*$detail[$i]['shuilv']*$detail[$i]['huilv']?></td>
	  <td>
	  	<?  
			if($detail[$i]['status'] == 0){
				echo '待确定';
			}
			elseif($detail[$i]['status'] == 1){
				echo '已出单';
			}
			elseif($detail[$i]['status'] == 2){
				echo '已取消';
			}
		?>
      </td>
	  <td><? echo $detail[$i]['date']?></td>
	  <td><? echo $emp_list[$detail[$i]['agent']]?></td>
	  <td>
      	  <a href="../detail-edit.php?nid=<?php echo $detail[$i]['nid']?>&nav-itemed=order" class=" layui-btn  layui-btn-sm" >
			  <i class="fa fa-eye" aria-hidden="true"></i>详情</a>
	<?php 
		if($detail[$i]['order_status'] == 0){?>
			<a href="javascript:void(0)" onclick="canItem (<?php echo $detail[$i]['nid']?>)" class="delete layui-btn   layui-btn-sm cancel_order" ><i class="fa fa-stop-circle-o" aria-hidden="true"></i>取消 </a>
	<?php }?>

          <a class="layui-btn  layui-btn-sm" href="/api/make-order-excel.php?sn=<?echo $detail[$i]['order_sn'] ?>"><i class="fa fa-file-excel-o" aria-hidden="true"></i>导出</a>

  	  </td>
    </tr>
  <?php

}
?>
  </tbody>
</table>

</div>






<script type="text/javascript">

// TODO 取消订单之后，不用返回订金金额，只改变订单状态即可。
// TODO 取消订单之后，对应列表的显示状态要更新

$('#cancel_order').click(function(){
	
	nid = '';
	$.each($("input[name='nid[]']"),function(){
          if(this.checked){
			 if( $(this).parent().parent().hasClass('cancel_order'))
             {
				if(nid != ''){
					nid+= ','+$(this).val();
				}
				else{
					nid+= $(this).val()
				}
			 }
			 else{
				$(this).attr('checked',false).next().removeClass('layui-form-checked')
			}
			 
          }
    });
	
	con=confirm("确认取消订单?");
	if(con==true){
		$.ajax({
				type:"POST",
				url:"cancel.php",
				dateType:"json",
				data:{"nid":nid,"act":'all_in'},
                dataType:"json",
				beforeSend: function () {
                      layer.msg('正在检查状态中');
                           
               	}, 
				success:function(data){
								
						
					alert(data.content)
						location.reload()
					
					
						
				}
		})	
	}
})

</script>






    <div class="list-box-function"
        <? if ($detailnum == 0) {
            echo "style" . "='display:none'";
        } ?>
        >

        <?php include 'page_numbers.php'; ?>

    </div>
</div>


<!--list-box end-->
</div>

<!--content端點01-->
</div>
<!--maincontent端點01-->
<br class="clearfloat"/>
</div>
<!--container端點01-->
</div>



<!--//todo 清查这部分是否没有用。是从给点餐系统中一直过来的吗？-->
<script>

 
 
    function canItem (id) {

        con=confirm("确认取消订单?");
        if(con==true){
				
			if(!id > 0 ){
				layer.msg('请刷新后再操作！');
				return false;
			}              
			
			
			$.ajax({
				type:"POST",
				url:"cancel.php",
				dateType:"json",
				data:{"nid":id},
                dataType:"json",
				beforeSend: function () {
                      layer.msg('正在检查状态中');
                           
               	}, 
				success:function(data){
								
						if(data.error == 1){
							layer.msg(data.content, {icon: 2}); 
						}
						else if(data.error == 0){
							layer.msg(data.content, {icon: 1}); 
							$('#item'+id).find('.state').html('取消')
							$('#item'+id).find('.cancel_order').remove()
						}
						
				}
			})	
    

        }

    }

</script>


<!--删除box-->
<?php include '../module/deletebar.php'; ?>
<!--删除box end-->

<?php include ROOT_PATH_ . "/controller/common/module/footer.php"; ?> </body>
</html>
